<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="true" name="HandheldFriendly">
    <title></title>
    <meta content="" name="keywords"/>
    <meta content="" name="description"/>
    <link href="/web/css/normalize.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/style.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/animate.css" rel="stylesheet" type="text/css"/>
    <link href="/web/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="/web/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <div class="contain">
        <div class="sidebar" id="head"></div>
        <section>
            <div class="right_h" id="right_h"></div>
            <div class="qulicklink">
                <ul>
                    <li><a href="javascript:;"></a></li>
                    <li><a href="javascript:;"><span>企业首页</span><img src="../web/images/close.png"></a></li>
                    <li class="dq"><a href="javascript:;"><span>业务管理</span><img src="../web/images/close.png"></a></li>
                    <li><a href="javascript:;"></a></li>
                </ul>
            </div>
            <div class="breadcrumbs">
                <ul>
                    <li>业务管理</li>
                    <li>业务合同</li>
                </ul>
            </div>
            <div class="clearfix"></div>
            <div class="content">
                <div class="addbtn" v-if="sum(54)">
                    <a @click="addbtnClick()" href="javascript:;">新增</a>
                </div>
                <div class="deletebtn" v-if="sum(56)">
                    <a @click="deleteAllClick()" href="javascript:;">删除</a>
                </div>
                <div class="importbtn" v-if="sum(57)">
                    <a @click="importClick()" href="javascript:;">导入</a>
                </div>
                <!--                <div class="adSearchbtn" v-if="sum(1101)">-->
                <!--                    <a @click="adSearchbtnClick()" href="javascript:;">高级搜索</a>-->
                <!--                </div>-->
                <!--高级搜索下拉框开始-->
                <!--                <div class="searchBox">-->
                <!--                    <div class="searchKey">-->
                <!--                        <label>-->
                <!--                            <span>客户名称:</span><input name="resetval" placeholder="请输入客户名称" type="text"/>-->
                <!--                        </label>-->
                <!--                        <label>-->
                <!--                            <span>开始日期:</span>-->
                <!--                            <div class="layui-input-inline">-->
                <!--                                <input class="layui-input" id="date1" name="resetval" placeholder="yyyy-MM-dd"-->
                <!--                                       type="text">-->
                <!--                            </div>-->
                <!--                        </label>-->
                <!--                        <label>-->
                <!--                            <span>签订日期:</span>-->
                <!--                            <div class="layui-input-inline">-->
                <!--                                <input class="layui-input" id="date2" name="resetval" placeholder="yyyy-MM-dd"-->
                <!--                                       type="text">-->
                <!--                            </div>-->
                <!--                        </label>-->
                <!--                        <label>-->
                <!--                            <span>合同名称:</span>-->
                <!--                            <input name="resetval" placeholder="请输入合同名称" type="text"/>-->
                <!--                        </label>-->
                <!--                        <label>-->
                <!--                            <span>到期日期:</span>-->
                <!--                            <div class="layui-input-inline">-->
                <!--                                <input class="layui-input" id="date3" name="resetval" placeholder="yyyy-MM-dd"-->
                <!--                                       type="text">-->
                <!--                            </div>-->
                <!--                        </label>-->
                <!--                        <label>-->
                <!--                            <span>签订人:</span>-->
                <!--                            <div class="layui-input-block">-->
                <!--                                <select id="departPosition" lay-filter="batch" lay-search="required"-->
                <!--                                        lay-verify="required" name="resetval">-->
                <!--                                    <option class="promptColor" value="">请选择签订人</option>-->
                <!--                                    <option>马冬梅</option>-->
                <!--                                    <option>夏洛</option>-->
                <!--                                </select>-->
                <!--                            </div>-->
                <!--                        </label>-->
                <!--                    </div>-->
                <!--                    <div class="btns">-->
                <!--                        <div class="addbtn searchbtn">-->
                <!--                            <a @click="searchbtnClick()" href="javascript:;">搜索</a>-->
                <!--                        </div>-->
                <!--                        <div class="addbtn setbtn">-->
                <!--                            <a @click="resetbtnClick()" href="javascript:;">重置</a>-->
                <!--                        </div>-->
                <!--                    </div>-->
                <!--                </div>-->
                <!--高级搜索下拉框结束-->
                <div class="search">
                    <!--模糊查询开始-->
                    <label>
                        <span>搜索:</span>
                        <div class="searchbox">
                            <input @input="search($event)" placeholder="请输入您要搜索关键字" type="text">
                        </div>
                    </label>
                    <!--模糊查询结束-->
                </div>
                <!-- 这里是新增编辑弹出框开始-->
                <div class="offerBox hidden">
                    <div class="layerbody">
                        <div class="address">
                            <label>
                                <span>客户名称:</span> <input :value="(cumval)" @click="customerListchange()"
                                                          autocomplete="off"
                                                          class="cum_name" name="resetTc"
                                                          placeholder="客户名称" type="text"/>
                            </label>
                        </div>
                        <label>
                            <span>合同名称:</span> <input autocomplete="off" class="htname" name="resetTc"
                                                      placeholder="合同名称"
                                                      type="text"/>
                        </label>
                        <label>
                            <span>合同金额:</span> <input id="contractprice" readonly autocomplete="off" class="htmoney htmoneybg" name="resetTc"
                                                      placeholder="0.0"
                                                      type="text"/>
                        </label>
                        <label>
                            <span>实际金额:</span> <input autocomplete="off" class="saleprice" name="resetTc"
                                                      placeholder="0.0"
                                                      type="text"/>
                        </label>
                        <label>
                            <span>付款次数:</span> <input autocomplete="off" class="fkcunt" name="resetTc"
                                                      placeholder="请输入付款次数" type="number"/>
                        </label>
                        <label>
                            <span>部门:</span>
                            <div class="layui-input-block">
                                <select @change="departmentchange1($event)" id="characterid1" lay-filter="batch"
                                        lay-search="required" lay-verify="required" name="resetTc" v-model="(characterid1)">
                                    <option class="promptColor" value="0">请选择部门</option>
                                    <option :value="v.id" v-for="(v,k) in ajaxData.character">{{v.title}}</option>
                                </select>
                            </div>
                        </label>
                        <label>
                            <span>签订人员:</span>
                            <div class="layui-input-block">
                                <select autocomplete="off" class="person" id="departPosition"
                                        lay-filter="batch" lay-search="required" lay-verify="required" name="resetTc"
                                        v-model="userid">
                                    <option class="promptColor" value="0">请选择签订人员</option>
                                    <option :value="v.id" v-for="(v,k) in user1">{{v.realname}}</option>
                                </select>
                            </div>
                        </label>
                        <label>
                            <span>部门:</span>
                            <div class="layui-input-block">
                                <select @change="departmentchange2($event)" id="characterid2" lay-filter="batch"
                                        lay-search="required" lay-verify="required" name="resetTc" v-model="(characterid2)">
                                    <option class="promptColor" value="0">请选择部门</option>
                                    <option :value="v.id" v-for="(v,k) in ajaxData.character">{{v.title}}</option>
                                </select>
                            </div>
                        </label>
                        <label>
                            <span>客服人员:</span>
                            <div class="layui-input-block">
                                <select autocomplete="off" class="personnel" id="departPosition"
                                        lay-filter="batch" lay-search="required" lay-verify="required" name="resetTc"
                                        v-model="serviceid">
                                    <option class="promptColor" value="0">请选择客服人员</option>
                                    <option :value="v.id" v-for="(v,k) in user2">{{v.realname}}</option>
                                </select>
                            </div>
                        </label>
                        <label>
                            <span>支付方式:</span>
                            <div class="layui-input-block">
                                <select autocomplete="off" class="paytype" id="departPosition"
                                        lay-filter="batch" lay-search="required" lay-verify="required" name="resetTc"
                                        v-model="paytypeid">
                                    <option class="promptColor" value="0">请选择支付的方式</option>
                                    <option :value="v.id" v-for="(v,k) in ajaxData.paytype">{{v.title}}</option>
                                </select>
                            </div>
                        </label>
                        <label>
                            <span>开始时间:</span>
                            <div class="layui-input-inline">
                                <input autocomplete="off" class="layui-input startime" id="startime" name="resetTc"
                                       placeholder="yyyy-MM-dd" type="text">
                            </div>
                        </label>
                        <label>
                            <span>签订时间:</span>
                            <div class="layui-input-inline">
                                <input autocomplete="off" class="layui-input signedtime" id="signedtime" name="resetTc"
                                       placeholder="yyyy-MM-dd" type="text">
                            </div>
                        </label>
                        <label>
                            <span>结束时间:</span>
                            <div class="layui-input-inline">
                                <input autocomplete="off" class="layui-input endtime" id="endtime" name="resetTc"
                                       placeholder="yyyy-MM-dd" type="text">
                            </div>
                        </label>
                        <label>
                            <span>合同编号:</span>
                            <input autocomplete="off" class="htmoneybg" id="htnumber" name="resetTc"
                                   placeholder="合同编号"
                                   type="text"/>
                        </label>
<!--                        <label>-->
<!--                            <span>上传附件:</span>-->
<!--                            <input @change="uploadImg($event)"-->
<!--                                   accept="image/gif, image/jpeg, application/pdf, aplication/zip, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint"-->
<!--                                   class="upload" multiple="multiple"-->
<!--                                   type="file"/>-->

<!--                        </label>-->
                        <div class="address">
                            <label>
                                <span>合同条款:</span>
                                <textarea autocomplete="off" class="termscon" name="resetTc" placeholder="合同条款"
                                          resize="" rows="4"></textarea>
                            </label>
                        </div>
                        <div class="address">
                            <label>
                                <span>备注:</span>
                                <textarea autocomplete="off" class="notecon" name="resetTc" placeholder="添加备注"
                                          resize="" rows="1"></textarea>
                            </label>
                        </div>
                        <div class="clearfix"></div>
                        <div class="newsTab">
                            <div class="layui-tab" v-if="edid != 0">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">产品明细</li>
<!--                                    <li>开发内容明细</li>-->
                                </ul>
                                <div class="layui-tab-content">
                                    <!--产品明细&#45;&#45;&#45;&#45;start-->
                                    <div class="layui-tab-item layui-show">
                                        <div class="itemBtn">
                                            <div class="itemadd">
                                                <a @click="addproductlist" href="javascript:;">添加</a>
                                            </div>
                                            <div class="itemdelete">
                                                <a @click="productdel" href="javascript:;">删除</a>
                                            </div>
                                        </div>
                                        <ul class="itemList">
                                            <li class="listBg">
                                                <ol><input type="text"/></ol>
                                                <ol>产品名称</ol>
                                                <ol>单位</ol>
                                                <ol>描述</ol>
                                                <ol>价格</ol>
                                                <ol>数量</ol>
                                                <ol>小计</ol>
                                            </li>
                                            <li v-for="(v,k) in productTableDataList">
                                                <ol><input :id="'productTableDataList' + (v.id)" type="checkbox"/></ol>
                                                <ol><input :value="v.title" @input="productedit($event,v.id,'title')"
                                                           class="itemtext pro_title" type="text"/>
                                                </ol>
                                                <ol><input :value="v.company"
                                                           @input="productedit($event,v.id,'company')"
                                                           class="itemtext pro_company"
                                                           type="text"/></ol>
                                                <ol><input :value="v.main" @input="productedit($event,v.id,'main')"
                                                           class="itemtext pro_specifications" type="text"/>
                                                </ol>
                                                <ol><input :id="'price' + v.id" :value="v.price"
                                                           @input="productedit($event,v.id,'price')"
                                                           class="itemtext pro_price" type="text"/>
                                                </ol>
                                                <ol><input :id="'num' + v.id" :value="v.num"
                                                           @input="productedit($event,v.id,'num')"
                                                           class="itemtext pro_num" type="text"/></ol>
                                                <ol><input :id="'countprice' + v.id" :value="v.countprice"
                                                           @input="productedit($event,v.id,'countprice')"
                                                           class="itemtext pro_countprice"
                                                           readonly type="text"/></ol>
                                            </li>
                                        </ul>
                                    </div>
                                    <!--                                    产品明细&#45;&#45;&#45;&#45;end-->
                                    <div class="layui-tab-item">
                                        <div class="itemBtn">
                                            <div class="itemadd">
                                                <a @click="addnewWindow()" href="javascript:;">添加</a>
                                            </div>
                                            <div class="itemdelete">
                                                <a @click="developdel" href="javascript:;">删除</a>
                                            </div>
                                        </div>
                                        <ul class="itemList itemList1">
                                            <li class="listBg">
                                                <ol><input type="checkbox"/></ol>
                                                <ol class="codenum">开发内容名称</ol>
                                                <ol>数量</ol>
                                                <ol>单价</ol>
                                                <ol class="codenum">开发内容明细</ol>
                                            </li>
                                            <li @dblclick="addnewWindow(v.id)" v-for="(v,k) in davelopDataList">
                                                <ol><input :id="'davelopDataList' + (v.id)" type="checkbox"/></ol>
                                                <ol class="codenum">{{v.title}}</ol>
                                                <ol>{{v.num}}</ol>
                                                <ol>{{v.price}}</ol>
                                                <ol class="codenum">{{v.content}}</ol>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            <button @click="addsureBtn()" class="surebtn" type="submit">确认</button>
                            <button @click="addresetBtn()" class="resetbtn" type="submit">重置</button>
                        </div>
                    </div>
                </div>
                <!-- 这里是新增编辑弹出框结束-->

                <!--开发内容明细弹窗开始-->
                <div class="offerboxwin hidden">
                    <div class="addtitle">订单信息</div>
                    <div class="layerbody">
                        <label>
                            <span>内容名称：</span>
                            <input autocomplete="off" class="dname" id="title" name="resetTc"
                                   placeholder="请输入开发内容名称" type="text"/>
                        </label>
                        <label>
                            <span>数量：</span>
                            <input autocomplete="off" class="num" id="num" name="resetTc" placeholder="请输入合作项目数量"
                                   type="text"/>
                        </label>
                        <label>
                            <span>单价：</span>
                            <input autocomplete="off" class="price" id="price" name="resetTc" placeholder="请输入单价"
                                   type="text"/>
                        </label>
                        <div class="address textbox">
                            <label>
                                <span>内容明细：</span>
                                <textarea autocomplete="off" class="details" id="content" name="resetTc" placeholder="添加明细"
                                          resize="" rows="4"></textarea>
                            </label>
                        </div>
                        <button @click="addnewWindowsave()" class="surebtn" type="submit">确认</button>
                        <button @click="addresetBtn()" class="resetbtn" type="submit">重置</button>
                    </div>
                </div>
                <!--开发内容明细弹窗结束-->

                <!--客户名称弹窗开始-->
                <div class="customerName hidden">
                    <div class="search">
                        <!--模糊查询开始-->
                        <label>
                            <span>客户名称:</span>
                            <div class="searchbox">
                                <input @input="searchWin($event,'archives','title')" placeholder="请输入您要搜索的客户名称"
                                       type="text"/>
                            </div>
                        </label>
                        <!--模糊查询结束-->
                    </div>
                    <div class="layerbody">
                        <ul class="customerNameList">
                            <li class="customerbg">
                                <ol>客户名称</ol>
                                <ol>联系电话</ol>
                                <ol>联系人</ol>
                                <ol>网址</ol>
                            </li>
                            <li @dblclick="doubleClickEvent(v.id,v.title,v.fromid)" v-for="(v,k) in ajaxData.archives">
                                <ol class="cumname">{{v.title}}</ol>
                                <ol>{{v.tel}}</ol>
                                <ol>{{v.contacts}}</ol>
                                <ol>{{v.link}}</ol>
                            </li>
                        </ul>
                    </div>
                </div>
                <!--客户名称弹窗结束-->

            </div>
            <div class="t_body">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                        <tr>
                            <th><input @click="deleteCheckAll()" class="checkboxAll" id="deleteCheckAll"
                                       type="checkbox"> 全选
                            </th>
                            <th>合同名称</th>
                            <th>合同编号</th>
                            <th>客户名称</th>
                            <th>销售金额</th>
                            <th>已收金额</th>
                            <th>未收金额</th>
                            <th>付款次数</th>
                            <th>客服人员</th>
                            <th>开始时间</th>
                            <th>结束时间</th>
                            <th>签订时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr :key="index" @dblclick="editorClick(v.id)" v-for="(v,index) in tableDataList">
                            <td><input :id="'listcheck' + (v.id)" class="selectCheck" type="checkbox"></td>
                            <td>{{v.title}}</td>
                            <td>{{v.code}}</td>
                            <td>{{v.customer}}</td>
                            <td>{{v.saleprice}}</td>
                            <td>{{v.alreadyprice}}</td>
                            <td>{{parseInt(v.saleprice - v.alreadyprice)}}</td>
                            <td>{{v.paycount}}</td>
                            <td>{{v.servicename}}</td>
                            <td>{{v.contractstarttime}}</td>
                            <td>{{v.contractendtime}}</td>
                            <td>{{v.successtime}}</td>
                            <td>
                                <div class="editor" v-if="sum(55)">
                                    <a @click="editorClick(v.id)" href="javascript:;">
                                        <img src="images/editor.png">
                                    </a>
                                    <span>编辑</span>
                                </div>
                                <div class="deletes" v-if="sum(56)">
                                    <a @click="deletesClick(v.id)" href="javascript:;">
                                        <img src="images/deletes.png">
                                    </a>
                                    <span>删除</span>
                                </div>
                                <div class="download">
                                    <a @click="downloadClick(v.id)" href="javascript:;">
                                        <img src="images/download.jpg">
                                    </a>
                                    <span>下载</span>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <!--下载的弹窗开始-->
                <div class="downLoadBox hidden">
                    <div class="layuiBtns">
                        <div class="addbtn">
                            <label class="ui_button ui_button_primary" for="xFile">上传文件</label>
                            <form><input @change="uploadImg($event)" id="xFile" style="position:absolute;clip:rect(0 0 0 0);" accept="image/gif, image/jpeg, application/pdf, aplication/zip, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint" class="upload" multiple="multiple" type="file"/></form>
                        </div>
                    </div>
                    <div class="layerbody">
                        <ul class="downLoadList">
                            <li class="downLoadbg">
                                <ol>文件名</ol>
                                <ol>操作</ol>
                                <ol>操作</ol>
                            </li>
                            <li v-for="(v,index) in ajaxData">
                                <ol>{{v.name}}</ol>
                                <ol><a :href="v.url" target="_blank" :download="'文件' + index + 1">下载</a></ol>
                                <ol><a href="javascript:;" @click="deletefile(v.url,v.id)">删除</a></ol>
                            </li>
                        </ul>
                    </div>
                </div>
                <!--下载的弹窗结束-->
                    <div class="statistical">
                        <ul>
                            <li>销售额: <span>{{sales}}</span></li>
                            <li>已收款: <span>{{receiving}}</span></li>
                            <li>未收款: <span>{{payment}}</span></li>
                        </ul>
                    </div>
                <!---------------------------分页start----------------------------->
                <div class="pageFen" v-if="totalNum>1">
                    <ul>
                        <li>
                            <a @click="setPage(curNum-1)" class="pageLink" href="#">上一页</a>
                        </li>
                        <li v-for="n in totalNum">
                            <a class="pageLink curNum" v-if="n == curNum" v-text="n"></a>
                            <a @click="setPage(n)" class="pageLink" href="javascript:;" v-else v-text="n"></a>
                        </li>
                        <li><a @click="setPage(curNum+1)" class="pageLink" href="#">下一页</a></li>
                    </ul>
                </div>
                <!---------------------------分页end-------------------------------->
            </div>
        </section>
    </div>
</div>
<script src="/web/js/vue.js"></script>
<script src="/web/js/jquery-1.10.0.min.js"></script>
<script src="/web/layui/layui.js"></script>
<script src="/web/js/transform.js"></script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //录入时间
        laydate.render({
            elem: '#startime', //指定元素
            type: "date", // 组件的类型：year,month,time···
            format: 'yyyy-MM-dd'// 设置显示格式
        });
        //最后跟进时间
        laydate.render({
            elem: '#signedtime', //指定元素
            type: "date", // 组件的类型：year,month,time···
            format: 'yyyy-MM-dd'// 设置显示格式
        });
        //最后跟进时间
        laydate.render({
            elem: '#endtime', //指定元素
            type: "date", // 组件的类型：year,month,time···
            format: 'yyyy-MM-dd'// 设置显示格式
        });
        //服务到期时间
        laydate.render({
            elem: '#serverendtime', //指定元素
            type: "date", // 组件的类型：year,month,time···
            format: 'yyyy-MM-dd'// 设置显示格式
        });
    });
</script>
<script>
    layui.use('element', function () {
        var element = layui.element;
    });
</script>
<script>
    AppData = new Vue({
        el: '#app',
        data: {
            tableData: {},
            categoryIndex: 0,
            show: false,
            tableDataList: {},
            dataList: {},
            totalNum: 0, //总页数
            listRows: 8, //每页数量
            curNum: 1, //当前页码
            characterid: 2,
            characterid1: 0,
            characterid2: 0,
            archivesid: 0,
            image: [],
            ajaxData: {},
            user1: {},
            user2: {},
            map: {},
            archivesList: {},
            cumval: '',
            serviceid: 0,
            paytypeid: 0,
            contracttypeid: 0,
            userid: 0,
            edid: 0,
            productTableDataList: [],
            davelopDataList: {},
            addnewWindoworedit: '',
            addoredit: 0,
            mylay: '',
            sales: 0,
            receiving: 0,
            payment: 0
        },
        mounted() {
            $("#head").load("header.html");
            $("#right_h").load("right.html");
            this.getIndexData();
        },
        methods: {
            verification(data) {
                if (data.status == 2) {
                    layer.msg(data.message, {icon: 2, time: 1000}, function () {
                        window.location.href = "login.html";
                    });
                }
            },
            deletesClick(deleteid) {
                layui.use('layer', function () {
                    layer.confirm('确认要删除吗？', {
                        btn: ['确定', '取消']//按钮
                    }, function () {
                        let ids = [];
                        ids.push(deleteid);
                        $.ajax({
                            type: "DELETE",
                            dataType: "json",
                            url: '/contract/0',
                            data: {'ids': ids},
                            success: function (data) {
                                AppData.verification(data);
                                if (data.status == 1) {
                                    layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                        //重新加载列表
                                        AppData.getIndexData();
                                    });
                                } else {
                                    layer.msg(data.message, {icon: 2, time: 1000});
                                }
                            },
                            error: function (msg) {
                                console.log(msg);
                            }
                        });
                    });
                });
            },
            deleteCheckAll() {
                let checkBoxs = AppData.tableDataList;
                if ($('#deleteCheckAll').is(":checked")) {
                    for (let j in checkBoxs) {
                        $('#listcheck' + checkBoxs[j].id).prop('checked', true);
                    }
                } else {
                    for (let j in checkBoxs) {
                        $('#listcheck' + checkBoxs[j].id).prop('checked', false);
                    }
                }
            },
            deleteAllClick() {
                layui.use('layer', function () {
                    layer.confirm('确认要删除吗？', {
                        btn: ['确定', '取消']//按钮
                    }, function () {
                        let ids = [];
                        let checkBoxs = AppData.tableDataList;
                        for (let i in checkBoxs) {
                            if ($('#listcheck' + checkBoxs[i].id).is(":checked")) {
                                ids.push(checkBoxs[i].id);
                            }
                        }
                        if (ids.length == 0) {
                            layer.msg('请选择你要删除的选项');
                            return false;
                        }
                        console.log(ids);
                        $.ajax({
                            type: "DELETE",
                            dataType: "json",
                            url: '/contract/0',
                            data: {'ids': ids},
                            success: function (data) {
                                console.log(data);
                                AppData.verification(data);
                                if (data.status == 1) {
                                    layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                        //重新加载列表
                                        AppData.getIndexData();
                                    });
                                } else {
                                    layer.msg(data.message, {icon: 2, time: 1000});
                                }
                            },
                            error: function (msg) {
                                console.log(msg);
                            }
                        });
                    });
                });
            },
            setPage(num) {
                //页码小于等于1
                if (num < 1) {
                    num = 1;
                }
                //页码大于总页数
                if (num > this.totalNum) {
                    num = this.totalNum;
                }
                //页码赋给当前页
                this.curNum = num;
                this.getIndexData();
            },
            search(e) {
                var that = this;
                var keywords = e.target.value;
                this.map.title = keywords;
                this.getIndexData();
            },
            searchWin(e, table, field) {//客户列表搜索名称
                var that = this;
                var keywords = e.target.value;
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/keyword',
                    data: {'table': table, 'field': field, 'keywords': keywords},
                    success: function (data) {
                        AppData.archivesList = data.list;
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            },
            sum(sumid) { //验证列表里的修改删除是否要显示(根据对应的id)
                for (i in this.dataList) {
                    if (sumid == this.dataList[i].id) {
                        return true;
                    }
                }
                return false;
            },
            adSearchbtnClick() {
                $('.searchBox').slideToggle();
                $('.search').toggle();
            },
            resetbtnClick() {
                $('input[name="resetval"]').val('');
                $('select[name="resetval"]').val('0');
            },
            addresetBtn() {
                $('input[name="resetTc"]').val('');
                $('select[name="resetTc"]').val('0');
                $('textarea[name="resetTc"]').val('');
                this.cumval = '';
                this.userid = 0;
                this.serviceid = 0;
                this.paytypeid = 0;
                this.contracttypeid = 0;
            },
            customerListchange() {//点击客户名称列表
                this.mylay = layer.open({
                    type: 1,
                    title: '选择客户',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    area: ['800px', '650px'],
                    id: 'layer03',
                    content: $('.customerName'),
                    success: function () {

                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.customerName').hide();
                    }
                })
            },
            addnewWindow(developid) {
                if (developid) {
                    this.addnewWindoworedit = developid;
                    //编辑
                    $.ajax({
                        type: "GET",
                        dataType: "json",
                        url: '/develop/' + developid,
                        data: {},
                        success: function (data) {
                            AppData.verification(data);
                            //编辑框赋值
                            $('#title').val(data.info.title);
                            $('#num').val(data.info.num);
                            $('#price').val(data.info.price);
                            $('#content').val(data.info.content);
                        },
                        error: function (msg) {
                        }
                    });
                } else {
                    this.addnewWindoworedit = 'add';
                }
                addnewWindow = parent.layer.open({
                    type: 1,
                    title: '开发内容明细',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    area: ['800px', '650px'],
                    id: 'layer02',
                    content: $('.offerboxwin'),
                    success: function () {
                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.offerboxwin').hide();
                    }
                })
            },
            addnewWindowsave() {
                var data = {
                    archivesid: this.edid,
                    title: $('#title').val(),
                    num: $('#num').val(),
                    price: $('#price').val(),
                    channel: 'contract',
                    content: $('#content').val()
                };
                if (this.addnewWindoworedit == 'add') {
                    //新增
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: '/develop',
                        data: data,
                        success: function (data) {
                            AppData.verification(data);
                            if (data.status == 1) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    //添加成功,重新加载列表
                                    AppData.getDevelopData();
                                    layer.close(addnewWindow);
                                });
                            } else {
                                layer.msg(data.message, {icon: 2, time: 1000});
                            }
                        },
                        error: function (msg) {
                        }
                    });
                } else {
                    //编辑
                    $.ajax({
                        type: "PUT",
                        dataType: "json",
                        url: '/develop/' + this.addnewWindoworedit,
                        data: data,
                        success: function (data) {
                            AppData.verification(data);
                            if (data.status == 1) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    //编辑成功,重新加载列表
                                    AppData.getDevelopData();
                                    layer.close(addnewWindow);
                                });
                            } else {
                                layer.msg(data.message, {icon: 2, time: 1000});
                            }
                        },
                        error: function (msg) {
                        }
                    });
                }

            },
            doubleClickEvent(archivesid, archivestitle, fromid) {//获取客户名称的双击事件
                this.cumval = archivestitle;
                this.archivesid = archivesid;
                this.fromid = fromid;
                // $.ajax({
                //     type: "GET",
                //     dataType: "json",
                //     url: '/product',
                //     data: {archivesid: this.archivesid},
                //     success: function (data) {
                //         AppData.productTableDataList = data.list.data;
                //     },
                //     error: function (msg) {
                //     }
                // });
                AppData.getDevelopData();
                layer.close(this.mylay);
            },
            addproductlist() {
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: '/product',
                    data: {archivesid: this.edid, channel: 'contract'},
                    success: function (data) {
                        if (data.status == 1) {
                            //添加完成,重新刷新列表
                            AppData.productload();
                        } else {
                            layer.msg(data.message, {icon: 2, time: 1000});
                        }
                    },
                    error: function (msg) {
                    }
                });
            },
            productedit(e, id, field) {
                var value = e.target.value;
                if (!$('#price' + id).val()) {
                    $('#price' + id).val(0);
                }
                if (!$('#num' + id).val()) {
                    $('#num' + id).val(0);
                }
                var countprice = $('#price' + id).val() * $('#num' + id).val();
                $('#countprice' + id).val(countprice);
                //开始编辑
                $.ajax({
                    type: "PUT",
                    dataType: "json",
                    url: '/product/' + id,
                    data: {field: field, value: value, countprice: countprice, channel: 'contract', archivesid: this.edid},
                    success: function (data) {
                        $('#contractprice').val(data.price);
                    },
                    error: function (msg) {
                    }
                });
            },
            productdel() {
                layui.use('layer', function () {
                    layer.confirm('确认要删除吗？', {
                        btn: ['确定', '取消']//按钮
                    }, function () {
                        let ids = [];
                        let checkBoxs = AppData.productTableDataList;
                        for (let i in checkBoxs) {
                            if ($('#productTableDataList' + checkBoxs[i].id).is(":checked")) {
                                ids.push(checkBoxs[i].id);
                            }
                        }
                        $.ajax({
                            type: "DELETE",
                            dataType: "json",
                            url: '/product/0',
                            data: {'ids': ids},
                            success: function (data) {
                                AppData.verification(data);
                                if (data.status == 1) {
                                    layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                        //删除成功,再次加载列表
                                        AppData.productload();
                                    });
                                } else {
                                    layer.msg(data.message, {icon: 2, time: 1000});
                                }
                            },
                            error: function (msg) {
                            }
                        });
                    });
                });
            },
            developdel() {
                layui.use('layer', function () {
                    layer.confirm('确认要删除吗？', {
                        btn: ['确定', '取消']//按钮
                    }, function () {
                        let ids = [];
                        let checkBoxs = AppData.davelopDataList;
                        for (let i in checkBoxs) {
                            if ($('#davelopDataList' + checkBoxs[i].id).is(":checked")) {
                                ids.push(checkBoxs[i].id);
                            }
                        }
                        $.ajax({
                            type: "DELETE",
                            dataType: "json",
                            url: '/develop/0',
                            data: {'ids': ids},
                            success: function (data) {
                                AppData.verification(data);
                                if (data.status == 1) {
                                    layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                        //删除成功,再次加载列表
                                        AppData.getDevelopData();
                                    });
                                } else {
                                    layer.msg(data.message, {icon: 2, time: 1000});
                                }
                            },
                            error: function (msg) {
                            }
                        });
                    });
                });
            },
            productload() {
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/product',
                    data: {archivesid: this.edid, channel: 'contract'},
                    success: function (data) {
                        console.log(data);
                        AppData.productTableDataList = data.list.data;
                    },
                    error: function (msg) {
                    }
                });
            },
            getDevelopData() {
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/develop',
                    data: {archivesid: this.edid, channel: 'contract'},
                    success: function (data) {
                        AppData.davelopDataList = data.list.data;
                    },
                    error: function (msg) {
                    }
                });
            },
            pricechange(e) {
                var value = e.target.value;
                if (!$('#orderprice').val()) {
                    $('#orderprice').val(0);
                }
                if (!$('#discountprice').val()) {
                    $('#discountprice').val(0);
                }
                var countprice = $('#orderprice').val() - $('#discountprice').val();
                $('#countprice').val(countprice);
            },
            //----------------------------------------------------------------------------------------------------------------------------------------------------------------
            //首页列表
            getIndexData() {
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/contract',
                    data: {'listRows': this.listRows, 'page': this.curNum, map:this.map},
                    success: function (data) {
                        console.log(data);
                        AppData.verification(data);
                        AppData.totalNum = data.list.last_page;  //获取总的页面数
                        AppData.dataList = data.userInfo.jurisdiction; //所有的权限
                        AppData.ajaxData = data;
                        let dataS = data.userInfo.jurisdiction;//后台初始数据
                        var dataArr = [];
                        for (let i in dataS) {
                            dataArr.push(dataS[i]); //属性
                        }
                        /*调用封装的改变数据结构方法*/
                        let tableData = setTreeData(dataArr);
                        let tableDataObj = {...tableData};//把转换后的数组通过扩展运算符改成对象便于遍历
                        AppData.tableData = tableDataObj;
                        //表格中数据的渲染
                        let tableList = {...data.list.data};
                        AppData.tableDataList = tableList;
                        //计算销售金额
                        let sum = 0;
                        let sum1 = 0;
                        for(var i in AppData.tableDataList){
                            sum += parseInt(AppData.tableDataList[i].saleprice);
                            sum1 += parseInt(AppData.tableDataList[i].alreadyprice);
                        }
                        AppData.sales = sum;
                        AppData.receiving = sum1;
                        AppData.payment = sum - sum1;
                    },
                    error: function (msg) {
                    }
                });
            },
            //新增按钮
            addbtnClick() {
                this.addresetBtn();
                this.edid = 0;
                this.davelopDataList = '';
                this.productTableDataList = '';
                layeraddoredit = layer.open({
                    type: 1,
                    title: '新增合同',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    area: ['900px', '830px'],
                    id: 'layer01',
                    content: $('.offerBox'),
                    success: function () {
                        //新增弹窗
                        $.ajax({
                            type: "GET",
                            dataType: "json",
                            url: '/contract/create',
                            data: {},
                            success: function (data) {
                                console.log(data);
                                AppData.verification(data);
                                AppData.ajaxData = data;
                                AppData.archivesList = {...data.archives};
                            },
                            error: function (msg) {
                                console.log(msg);
                            }
                        });

                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.offerBox').hide();
                    }
                })
            },
            //编辑按钮
            editorClick(edid) {
                this.edid = edid;
                layeraddoredit = layer.open({
                    type: 1,
                    title: '编辑菜单',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    area: ['900px', '830px'],
                    content: $('.offerBox'),
                    success: function () {
                        $.ajax({
                            type: "GET",
                            dataType: "json",
                            url: '/contract/' + edid,
                            data: {},
                            success: function (data) {
                                AppData.verification(data);
                                console.log(data);
                                AppData.ajaxData = data;
                                AppData.user1 = data.user;
                                AppData.user2 = data.user;
                                AppData.archivesList = {...data.archives};
                                AppData.archivesid = data.info.archivesid;
                                AppData.serviceid = data.info.serviceid;
                                AppData.userid = data.info.userid;
                                AppData.paytypeid = data.info.paytypeid;
                                AppData.contracttypeid = data.info.contracttypeid;
                                AppData.cumval = data.info.customer;
                                //文本框获取值
                                $('.htname').val(data.info.title);
                                $('.htmoney').val(data.info.contractprice);
                                $('.saleprice').val(data.info.saleprice);
                                $('.fkcunt').val(data.info.paycount);
                                $('.termscon').val(data.info.content);
                                $('.notecon').val(data.info.message);
                                $('#startime').val(data.info.contractstarttime);
                                $('#signedtime').val(data.info.successtime);
                                $('#endtime').val(data.info.contractendtime);
                                $('#serverendtime').val(data.info.serviceendtime);
                                //产品明细重新加载
                                AppData.productload();
                                // AppData.doubleClickEvent(data.info.archivesid, data.info.customer, data.info.fromid);
                                //开发明细重新加载
                                AppData.getDevelopData();
                            },
                            error: function (msg) {
                                console.log(msg);
                            }
                        });
                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.offerBox').hide();
                    }
                })
            },
            //新增编辑保存
            addsureBtn() {
                var data = {
                    title: $('.htname').val(),
                    customer: $('.cum_name').val(),
                    contractprice: $('.htmoney').val(),
                    paycount: $('.fkcunt').val(),
                    serviceid: $('.personnel').val(),
                    paytypeid: $('.paytype').val(),
                    contractstarttime: $('#startime').val(),
                    contractendtime: $('#endtime').val(),
                    successtime: $('#signedtime').val(),
                    contracttypeid: $('.contractype').val(),
                    content: $('.termscon').val(),
                    message: $('.notecon').val(),
                    saleprice: $('.saleprice').val(),
                    userid: $('.person').val(),
                    serviceendtime: $('#serverendtime').val(),
                    file: this.image,
                    archivesid: this.archivesid
                }
                if (this.edid == 0) { //新增
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: '/contract',
                        data: data,
                        success: function (data) {
                            AppData.verification(data);
                            if (data.status == 1) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    AppData.getIndexData();
                                    layer.close(layeraddoredit);
                                });
                            } else {
                                layer.msg(data.message, {icon: 2, time: 1000});
                            }
                        },
                        error: function (msg) {
                            console.log(msg);
                        }
                    });
                } else {
                    $.ajax({
                        type: "PUT",
                        dataType: "json",
                        url: '/contract/' + this.edid,
                        data: data,
                        success: function (data) {
                            AppData.verification(data);
                            if (data.status == 1) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    AppData.getIndexData();
                                    layer.close(layeraddoredit);
                                });
                            } else {
                                layer.msg(data.message, {icon: 2, time: 1000});
                            }
                        },
                        error: function (msg) {
                            console.log(msg);
                        }
                    });
                }
            },
            departmentchange1(e){
                var id = event.target.value;
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/order/' + id + '/edit',
                    data: {},
                    success: function (data) {
                        headerData.verification(data);
                        AppData.user1 = data.user;
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            },
            //下载文件按钮
            downloadClick(downloadid){
                this.downid = downloadid;
                downloadbox = layer.open({
                    type: 1,
                    title: '文件下载',
                    maxmin: true,
                    resize: true,
                    shadeClose: false, //点击遮罩关闭层
                    area: ['800px', '600px'],
                    id: 'downloadbox',
                    content: $('.downLoadBox'),
                    success: function () {
                        //加载文件列表
                        AppData.fileListData();
                    },
                    end: function () { //解决弹窗关闭以后,弹窗内容还出现在下方的问题
                        $('.downLoadBox').hide();
                    }
                })
            },
            fileListData(){
                $.ajax({
                    url: "/file/" + AppData.downid,
                    type: "GET",
                    dataType: "json",
                    data: {table: 'contract'},
                    success: function (data) {
                        AppData.ajaxData = data.list;
                    }
                });
            },
            uploadImg(event) { //上传文件事件
                AppData.image = event.target.files;
                let formData = new FormData();
                for (let i = 0; i < this.image.length; i++) {
                    formData.append('table', 'contract');
                    formData.append('pid', this.downid);
                    formData.append('image[]', this.image[i]);
                }
                $.ajax({
                    url: "/file",
                    type: "POST",
                    dataType: "json",
                    data: formData,
                    processData: false,
                    async: false,
                    contentType: false,
                    success: function (data) {
                        if (data.status == 1) {
                            layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                //上传成功,再次加载列表
                                AppData.fileListData();
                                //清空value
                                $('#xFile').val('');
                            });
                        } else {
                            layer.msg(data.message, {icon: 2, time: 1000});
                        }
                    }
                })
            },
            deletefile(url,id){
                $.ajax({
                    url: "/file/0",
                    type: "DELETE",
                    dataType: "json",
                    data: {url: url, fileid: id},
                    success: function (data) {
                        if (data.status == 1) {
                            layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                AppData.fileListData();
                            });
                        } else {
                            layer.msg(data.message, {icon: 2, time: 1000});
                        }
                    }
                });
            },
            departmentchange2(e){
                var id = event.target.value;
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: '/order/' + id + '/edit',
                    data: {},
                    success: function (data) {
                        headerData.verification(data);
                        AppData.user2 = data.user;
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            }
        }

    })
</script>
</body>
</html>
